package com.neo.demo.controller;

import com.neo.demo.service.mailService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class mailController {
    private final Logger logger=LoggerFactory.getLogger(this.getClass());
    @Autowired
    private mailService mailService;
//常规的测试能否正常发送邮件
    @RequestMapping("/send")
    public String sendSimpleMail(Model model){
        mailService.sendSimpleMail("2385797727@qq.com","make test now ","你好，我正在测试验证simpl登录");
        model.addAttribute("message","完成");
        logger.info("测试simple完毕");
        return "defind";

    }
//测试发送邮件，邮件格式是html格式
    @GetMapping("/sendHtml")
    public String sendHtmlMail(Model model)throws Exception{
        String content="<html>\n" +
                "<body>\n" +
                "    <h3>hello world ! 这是一封Html邮件!</h3>\n" +
                "</body>\n" +
                "</html>";
        mailService.sendHtml("2385797727@qq.com","make test now ",content);
        logger.info("测试完毕");
        model.addAttribute("message","html完成");
        return "defind";

    }
//测试发送邮件带附件的
    @GetMapping("/sendAttachmentsMail")
    public String sendAttachmentsMail(Model model){
        String filePath="F:\\浏览器下载\\QQ.jpg";
        mailService.sendAttachmentsMail("2385797727@qq.com", "主题：带附件的邮件", "有附件，请查收！", filePath);
        logger.info("测试完毕");
        model.addAttribute("message","html带附件测试完成");
        return "defind";
    }
}
